import Vue from 'vue'
import Vuex from 'vuex'
import {setAuthorization,removeAuthorization} from '../utils/auth.js'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		userInfo: {},
		hasLogin: false
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true
			state.userInfo.token = provider.token
			state.userInfo.userName = provider.user_name
			setAuthorization(provider)
		},
		logout(state) {
			state.hasLogin = false
			state.userInfo = {}
			removeAuthorization('userInfo')
		}
	}
})

export default store
